/*
 * @Author: lusx 
 * @Date: 2020-05-21 14:28:19 
 * @Last Modified by: lusx
 * @Last Modified time: 2020-05-22 13:44:57
 */
import { observable, action, computed, toJS } from 'mobx';
import { chunk } from 'lodash';
import { ListViewPage, ListPage } from 'weaver-mobile-page';
import { getProjectList } from "../../apis/govern";
export default class Overtime {
    @observable loading = false;
     _panelData = [
        { top: 1, bottom: '进行中', id: "0", to: '/quickbar/ongoing' },
        { top: 0, bottom: '已超期', id: "1", to: '/quickbar/overtime'  },
        { top: 0, bottom: '即将超期', id: "2", to: '/quickbar/will_overtime'  },
        { top: 0, bottom: '有新反馈', id: "3", to: '/quickbar/new_feedback'  },
        { top: 0, bottom: '有新批示', id: "4", to: '/quickbar/new_instruct'  },
        { top: 0, bottom: '有新催办', id: "5", to: '/quickbar/new_urgent'  }];
    @observable panelDatas = [];
    @observable listView = new ListViewPage.Store({ route: '/', id: '' });
    @observable list = new ListPage.Store();
    // @observable tabindex = 0;

    @action
    init = (params = { tasktype: '0' }) => {
        //console.log(params)
        // this.tabindex = params.tasktype;
        this.tabOnchange(params.tasktype);
        this.loading = true;
        this.bingfaRequest(params).then(([result1, result2]) => {
            if (result1.status === '1') {
                const { status, ...others } = result1;
                this._panelData[0].top =  others.ongoing;
                this._panelData[1].top =  others.overtime;
                this._panelData[2].top =  others.will_overtime;
                this._panelData[3].top =  others.new_feedback;
                this._panelData[4].top =  others.new_instruct;
                this._panelData[5].top =  others.new_urgent;
                this.panelDatas = chunk(this._panelData, 3);
            }
            if (result2.status === '1') {
                this.listView.getData({ 'dataKey': result2.sessionkey, 'pageSize': 5 });
            }
        })
            .catch(err => { console.error('err', err) })
            .finally(() => { this.loading = false })
    }
    // **********************tools函数***************************
    bingfaRequest = async (params) => {
        const flags = ['getnumber', 'top'];
        let promises = flags.map((flag) => getProjectList({ flag,...params }));
        let results = await Promise.all(promises);
        return results
    }
    // **********************************************************

    
    tabOnchange = (tasktype) =>{
        this._panelData.forEach((item,index)=>{
            item.to = item.to+'/'+tasktype;
        })
    }
}